package acwing.并查集;

import java.util.Scanner;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/11/17
 */
public class 合并集合 {

    static int N = 100010;
    static int[] p = new int [N];

    public static int find(int x) {
        if (p[x] != x) p[x] = find(p[x]);
        return p[x];
    }

    public static void main(String[] args) {
        Scanner sy = new Scanner(System.in);
        int n = sy.nextInt();
        int m = sy.nextInt();
        for(int i = 1;i<=n;i++)  p[i] = i;
        while(m-- != 0) {
            String s = sy.next();
            int a = sy.nextInt() , b = sy.nextInt();
            if (s.equals("M")) p[find(a)] = find(b);
            else {
                if(find(a) == find(b)) System.out.println("Yes");
                else System.out.println("No");
            }
        }
    }
}
